package com.winit.schedule.job.tracker.repository.mongo;

import com.winit.schedule.core.conf.Configuration;
import com.winit.schedule.core.repository.JobRepository;
import com.winit.schedule.core.repository.LoggerRepository;
import com.winit.schedule.core.repository.RepositoryEngine;
import com.winit.schedule.core.repository.TaskItemRepository;
import com.winit.schedule.core.repository.TaskRepository;
import com.winit.schedule.core.repository.TaskTrackerRepository;
import com.winit.schedule.job.tracker.conf.JobConfiguration;
import com.winit.schedule.store.Config;
import com.winit.schedule.store.mongo.DatastoreHolder;

public class MongoRepositoryImpl implements RepositoryEngine {

    private TaskTrackerRepository taskTrackerRepository;

    private TaskRepository        taskRepository;

    private TaskItemRepository    taskItemRepository;

    private JobRepository         jobRepository;

    private LoggerRepository      loggerRepository;

    public MongoRepositoryImpl(Configuration conf){
        Config config = new Config();
        config.setAddresses(conf.getStrings(JobConfiguration.MONGODB_ADDRESS));
        config.setDbName(conf.getString(JobConfiguration.MONGODB_DB, ""));
        config.setUsername(conf.getString(JobConfiguration.MONGODB_USERNAME, ""));
        config.setPassword(conf.getString(JobConfiguration.MONGODB_PASSWORD, ""));
        DatastoreHolder.setConfig(config);

        taskTrackerRepository = new MongoTaskTrackerRepository();
        taskRepository = new MongoTaskRepository();
        taskItemRepository = new MongoTaskItemRepository();
        jobRepository = new MongoJobRepository();
        loggerRepository = new MongoLoggerRepository();
    }

    @Override
    public JobRepository getJobRepository() {
        return jobRepository;
    }

    @Override
    public TaskRepository getTaskRepository() {
        return taskRepository;
    }

    @Override
    public TaskTrackerRepository getTaskTrackerRepository() {
        return taskTrackerRepository;
    }

    @Override
    public LoggerRepository getLoggerRepository() {
        return loggerRepository;
    }

    @Override
    public TaskItemRepository getTaskItemRepository() {
        return taskItemRepository;
    }

}
